package com.flats.service.transactional;

import com.flats.model.dao.Dao;
import com.flats.model.entity.Users;
import com.flats.service.UsersService;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;


public class TransactionalUserService implements UsersService {
    public Dao<Users> getUsersDao() {
        return usersDao;
    }

    public void setUsersDao(Dao<Users> usersDao) {
        this.usersDao = usersDao;
    }

    private Dao<Users> usersDao;

    @Override
    @Transactional
    public Serializable saveOrUpdate(Users persistent) {
//        System.out.println("persistent.getCabinet().getId() = " + persistent.getCabinet().getId());
        Serializable id = usersDao.saveOrUpdate(persistent);
        return id;
    }

    @Override
    @Transactional
    public void delete(Long id) {
       usersDao.delete(id);
    }

    @Override
    @Transactional
    public void delete(Users persistent) {
        usersDao.delete(persistent);
    }

    @Override
    @Transactional
    public Users get(Long id) {
        return usersDao.get(id);
    }

    @Override
    @Transactional
    public List<Users> getAll() {
        return usersDao.getAll();
    }
}
